<?php
/*
 * File content.php for project Rijlesplanner.nl
 * Created on 11 dec 2007 at 21:10:40 by Ivar Pruijn
 */
class content extends modules {
	// Properties:
	protected $name = "content";
	protected $title = "Content";
	protected $subtitle = "";
	private $errors = array ();
	protected $moduleOptions = array("overrijlesplanner","simulatorlessen");

	// Methods:

	/**
	 * void __construct ()
	 * This is the constructor method for this class.
	 */
	public function __construct() {
		parent :: __construct();
		$this->logger = parent :: getLogger();
		$this->user = parent :: getUser();
		$this->template = parent :: getTemplate();
	}

	/**
	 * Object process()
	 * 
	 * Processes the template and current module
	 * 
	 * @param Smarty template The Smarty template to process (sets variables etc.)
	 * @return Smarty The template that has been processed
	 */
	function process(& $template = null) {
		$this->template = $template;
		parent::loadModule("reviews",$template);
		parent::loadModule("ads",$template);
		
		if (!empty ($_POST)) {
			if (!$this->auth->accessTo($this->name,$_POST['action'])) {
				$this->actionAccessDenied();
			} else {
				switch ($_POST['action']) {
				}
			}
		} else if(!empty($_GET['option'])) {
			if (!$this->auth->accessTo($this->name,$_GET['option'])) {
				$this->optionAccessDenied();
			} else {
	  	  		switch ($_GET['option']) {
	  	    		case "voorrijscholen":
						$this->template->assign('moduleTemplate', 'modules/content/voorrijscholen.tpl');
	  	    			break;
	  	    		case "overrijlesplanner":
						$this->template->assign('moduleTemplate', 'modules/content/overrijlesplanner.tpl');
	  	    			break;
	  	    		case "simulatorlessen":
						if($this->user instanceof Visitor) {
							$this->title = "Rijles met simulator";
							$this->template->assign('moduleTemplate', 'modules/content/simulatorlessen_bezoeker.tpl');
						} else if ($this->user instanceof Leerling) {
							$this->title = "Rijles met simulator";
							$this->template->assign('moduleTemplate', 'modules/content/simulatorlessen_leerling.tpl');
						}
	  	    			break;
	  	    		default:
						$this->template->assign('moduleTemplate', 'modules/content/defaultcontent.tpl');
	  	    			break;
	  	  		}
			}
		} else {
			$this->template->assign('moduleTemplate', 'modules/content/defaultcontent.tpl');
		}
	}

	public function addError($message, $code) {
		$this->errors[] = array (
			'code' => $code,
			'message' => $message
		);
		$this->setSubtitle($message);
	}

	public function getTitle() {
		return $this->title;
	}

	public function getSubTitle() {
		if (!empty ($_GET['option'])) {
			$subtitle = "";
			foreach ($this->moduleOptions AS $mOpt) {
				if ($mOpt['name'] == $_GET['option']) {
					$subtitle = $mOpt['title'];
				}
			}
			return $subtitle;
		} else {
			return $this->subtitle;
		}
	}

	public function setSubTitle($newVal = "") {
		if (!empty ($newVal)) {
			$this->subtitle = $newVal;
		}
	}

	/*
	 * string __toString()
	 * 
	 * Returns a String representation of this class.
	 * 
	 * @return string A representation of this class
	 */
	public function __toString() {
		return $this->title;
	}
}
?>